<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@page import="org.springframework.data.domain.Page"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>查看客户信息</title>
<script>
function reset(){
	document.getElementById('datepicker2').value = formatDate(new Date());
	document.getElementById("datepicker2").value = "";
	document.getElementByName("customerName").value = "";
}
function jumpPage(pageNumber){
	document.getElementById('pageNumber').value = pageNumber;
}
</script>
<script>

$(document).ready(function() {
	//聚焦第一个输入框
	$("#customerName").focus();
	//为inputForm注册validate函数
	$("#inputForm").validate({
		rules: {
		}
	});
});

$(document).ready(function() {
	$("#message").fadeOut(5000);
});

</script>
</head>

<body>
	<h4 class="prepend-top">客户信息</h4>
	<c:if test="${not empty message}">
		<div id="message" class="success">${message}</div>
	</c:if>

	<form:form id="inputForm" modelAttribute="search"
		action="${ctx}/customer/search" method="post">
		<fieldset class="prepend-top">
			<legend>客户查询</legend>
			<div>
				<label for="customerName" class="field">客户名称:</label><input
					type="text" id="customerName" name="customerName" value="${search.customerName}" />
			</div>
			<input type="text" style="display: none;" id="pageNumber"
				name="pageNumber" size="40" value="${search.pageNumber}" />本查询支持模糊查询，例如：查询“上海文%” 将%号置于关键词后。
		</fieldset>
		<div>
			<input id="submit" onclick="jumpPage('research')"
				style="margin-left: 450px; text-align: center; width: 120px; height: 30px"
				type="submit" value="查    询" />&nbsp; <input id="reset"
				style="text-align: center; width: 120px; height: 30px" type="reset"
				value="重    置" onclick="reset()" />
		</div>
		<shiro:hasPermission name="customer:edit">
			<h4>
				<a href="create">创建客户</a>
			</h4>
		</shiro:hasPermission>

			<h3 class="prepend-top">客户查询结果</h3>
			<h5 align="right">共${pages.totalElements}条记录|共${pages.totalPages}页|当前${pages.number+1}页|每页${pages.size}条|</h5>
			<div align="right">
				<input id="firstone"
					<c:if test="${pages.firstPage}">disabled="disabled"</c:if>
					class="button" type="submit" onclick="jumpPage(0)" value="首页" />&nbsp;
				| <input id="preone"
					<c:if test='<%=!((Page)request.getAttribute("pages")).hasPreviousPage() %>'>disabled="disabled"</c:if>
					class="button" type="submit"
					onclick="jumpPage(${pages.number - 1})" value="上页" />&nbsp; | <input
					id="nextone"
					<c:if test='<%=!((Page)request.getAttribute("pages")).hasNextPage() %>'>disabled="disabled"</c:if>
					class="button" type="submit"
					onclick="jumpPage(${pages.number + 1})" value="下页" />&nbsp; | <input
					id="preone"
					<c:if test='${pages.lastPage}'>disabled="disabled"</c:if>
					class="button" type="submit"
					onclick="jumpPage(${pages.totalPages -1})" value="尾页" />&nbsp;
			</div>
			<table id="contentCustomerTable">
				<tr>
					<th align="center">ID</th>
					<th align="center">客户名称</th>
					<th align="center">住址</th>
					<th align="center">联系方式1</th>
					<th align="center">联系方式2</th>
					<th align="center">备注</th>
					<shiro:hasPermission name="customer:edit">
						<th width="10%" align="center">操作</th>
					</shiro:hasPermission>
				</tr>
				<c:forEach items="${customers}" var="customer">
					<tr>
						<td>${customer.id}</td>
						<td>${customer.name}</td>
						<td>${customer.address}</td>
						<td>${customer.contact1}</td>
						<td>${customer.contact2}</td>
						<td>${customer.remark}</td>
						<td><shiro:hasPermission name="customer:edit">
								<a href="update/${customer.id}" id="editLink-${customer.id}">修改</a>
							</shiro:hasPermission> <shiro:hasPermission name="customer:edit">
								<a href="delete/${customer.id}">删除</a>
							</shiro:hasPermission></td>
					</tr>
				</c:forEach>
			</table>
			<c:if test="${not empty pages}">
				<div align="right">
					<input id="firstone"
						<c:if test="${pages.firstPage}">disabled="disabled"</c:if>
						class="button" type="submit" onclick="jumpPage(0)" value="首页" />&nbsp;
					| <input id="preone"
						<c:if test='<%=!((Page)request.getAttribute("pages")).hasPreviousPage() %>'>disabled="disabled"</c:if>
						class="button" type="submit"
						onclick="jumpPage(${pages.number - 1})" value="上页" />&nbsp; | <input
						id="nextone"
						<c:if test='<%=!((Page)request.getAttribute("pages")).hasNextPage() %>'>disabled="disabled"</c:if>
						class="button" type="submit"
						onclick="jumpPage(${pages.number + 1})" value="下页" />&nbsp; | <input
						id="preone"
						<c:if test='${pages.lastPage}'>disabled="disabled"</c:if>
						class="button" type="submit"
						onclick="jumpPage(${pages.totalPages -1})" value="尾页" />&nbsp;
				</div>
			</c:if>
	</form:form>
</body>
</html>
